<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import goodsCategory from '@/api/goods/goodsCategory'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  goodsCategory.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  goodsCategory.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'goods_category',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: goodsCategory.getList,
  recycleApi: goodsCategory.getRecycleList,
  add: {
    show: true,
    api: goodsCategory.save,
    auth: ['goods:category:save']
  },
  edit: {
    show: true,
    api: goodsCategory.update,
    auth: ['goods:category:update']
  },
  delete: {
    show: true,
    api: goodsCategory.deletes,
    auth: ['goods:category:delete'],
    realApi: goodsCategory.realDeletes,
    realAuth: ['goods:category:realDeletes']
  },
  recovery: {
    show: true,
    api: goodsCategory.recoverys,
    auth: ['goods:category:recovery']
  },
  import: {
    show: true,
    url: 'goods/category/import',
    templateUrl: 'goods/category/downloadTemplate',
    auth: ['goods:category:import']
  },
  export: {
    show: true,
    url: 'goods/category/export',
    auth: ['goods:category:export']
  }
})

const columns = reactive([
  {
    title: "商品分类ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    commonRules: {
      required: true,
      message: "请输入商品分类ID"
    }
  },
  {
    title: "分类名称",
    dataIndex: "name",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入分类名称"
    }
  },
  {
    title: "上级分类ID",
    dataIndex: "parent_id",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入上级分类ID"
    }
  },
  {
    title: "分类图片",
    dataIndex: "var_image",
    formType: "upload",
    commonRules: {
      required: true,
      message: "请输入分类图片"
    },
    type: "image",
    multiple: false,
    onlyData: true,
    returnType: "url",
    chunk: false
  },
  {
    title: "状态(1显示 0隐藏)",
    dataIndex: "status",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入状态(1显示 0隐藏)"
    }
  },
  {
    title: "排序方式(数字越小越靠前)",
    dataIndex: "sort",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入排序方式(数字越小越靠前)"
    }
  },
  {
    title: "商城ID",
    dataIndex: "store_id",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入商城ID"
    }
  },
  {
    title: "创建时间",
    dataIndex: "create_time",
    formType: "input",
    search: true,
    addDisplay: false,
    editDisplay: false
  },
  {
    title: "更新时间",
    dataIndex: "update_time",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'goods:category' } </script>